﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using ImageConverter.Model.Enums;

namespace ImageConverter.Model
{
    public class ContainerItem : ItemBase
    {
        #region Properties

        public ItemStatusEnum Status
        {
            get
            {
                return itemStatus;
            }
            set
            {
                itemStatus = value;
                OnPropertyChanged("Status");
            }
        }

        public string FullName
        {
            get
            {
                return fullName;
            }
            set
            {
                fullName = value;
                OnPropertyChanged("FullName");
            }
        }

        public bool IsDirectory
        {
            get
            {
                return isDirectory;
            }
            private set
            {
                isDirectory = value;
                OnPropertyChanged("IsDirectory");
            }
        }

        public ObservableCollection<ContainerItemEntry> Entries
        {
            get
            {
                return entries;
            }
            set
            {
                entries = value;
                OnPropertyChanged("Entries");
            }
        }

        public Exception Error
        {
            get
            {
                return error;
            }
            set
            {
                error = value;
                OnPropertyChanged("Error");
            }
        }

        #endregion

        public ContainerItem(string fullName, bool isDirectory)
        {
            Entries = new ObservableCollection<ContainerItemEntry>();

            IsDirectory = isDirectory;
            Name = Path.GetFileName(fullName);
            FullName = fullName;
            Status = ItemStatusEnum.Unknown;
        }

        public void CreateEntries(IEnumerable<string> entryNames)
        {
            Entries = new ObservableCollection<ContainerItemEntry>();

            if (entryNames == null)
                return;

            int entryID = 1;
            foreach (var eName in entryNames)
            {
                ContainerItemEntry e = new ContainerItemEntry()
                {
                    Name = eName,
                    Status = ItemStatusEnum.Unknown,
                };

                Entries.Add(e);

                ++entryID;
            }
        }

        #region Private fields

        private ItemStatusEnum itemStatus;
        private string fullName;
        private ObservableCollection<ContainerItemEntry> entries;
        private Exception error;
        private bool isDirectory;

        #endregion
    }
}
